package net.maku.utils;

import java.util.concurrent.TimeUnit;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

public class CaffeineUtils {
	public static final int INIT_SIZE   = 5;
	public static final int MAX_SIZE    = 10;
    public static final int DEFAULT_TTL = 60;
 
    static final Cache<String, Object> payConfigCache = Caffeine.newBuilder()
            //cache的初始容量
            .initialCapacity(INIT_SIZE)
            //cache最大缓存数
            .maximumSize(MAX_SIZE)
            //设置写缓存后n秒钟过期
            .expireAfterWrite(DEFAULT_TTL, TimeUnit.MINUTES)
            //.expireAfterWrite(DEFAULT_TTL, TimeUnit.SECONDS)
            .build();

    public static Object getCache(String key) {
    	return payConfigCache.asMap().get(key);
    }
    
    public static void putCache(String key, Object value ) {
    	payConfigCache.put(key, value);
    }
}





